package main

import (
	"apitestAfterGo/common"
	"apitestAfterGo/controller"
	"apitestAfterGo/dao"
	"apitestAfterGo/middleWare"
	"github.com/go-playground/validator/v10"
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/middleware/logger"
	rotateLogs "github.com/lestrrat-go/file-rotatelogs"
	"os"
	"time"
)

func main() {
	//utils.XmlCreateTool()
	app := iris.New()
	path := common.LogPath
	writer, _ := rotateLogs.New(
		path+"%Y%m%d%H%M.log",
		rotateLogs.WithLinkName(path),
		rotateLogs.WithMaxAge(time.Duration(180)*time.Second),
		//这里设置1分钟产生一个日志文件
		rotateLogs.WithRotationTime(time.Duration(10)*time.Minute),
	)
	app.Logger().SetOutput(writer)    //日志写入文件
	app.Logger().AddOutput(os.Stdout) //日志同时写入控制台，如果不想显示控制台可注释此语句
	//记录路由日志
	app.Use(logger.New(logger.Config{
		Status:     true,
		IP:         true,
		Method:     true,
		Path:       true,
		Query:      true,
		LogFunc:    nil,
		LogFuncCtx: nil,
		Skippers:   nil,
	}))
	app.Validator = validator.New()
	middleWare.Init(app)
	controller.Init(app)
	db := dao.DatabaseInit()
	defer db.Close()
	app.Listen(common.Port)
}
